package sdk.webview.fmc.com.fmcsdk.check.persenter;


import java.util.HashMap;
import java.util.Map;

import sdk.webview.fmc.com.fmcsdk.base.BasePresenter;
import sdk.webview.fmc.com.fmcsdk.base.UserApi;
import sdk.webview.fmc.com.fmcsdk.check.bean.RunListPagerBean;
import sdk.webview.fmc.com.fmcsdk.check.bean.WorkHistoryBean;
import sdk.webview.fmc.com.fmcsdk.check.interfaces.HealthHistoryView;
import sdk.webview.fmc.com.fmcsdk.check.interfaces.WorkHistoryView;
import sdk.webview.fmc.com.fmcsdk.util.StringUtils;
import sdk.webview.fmc.com.fmcsdk.util.Url;
import sdk.webview.fmc.com.fmcsdk.util.UserHelper;
import sdk.webview.fmc.com.fmcsdk.util.retrofit2.observer.ResponseTransformer;
import sdk.webview.fmc.com.fmcsdk.util.retrofit2.subscriber.ResponseSubscriber;

/**
 * Created by ydm on 2017/9/14.
 */

public class HealthHistoryPersenter extends BasePresenter<HealthHistoryView> {
    private int pageNum = 1;
    private int pageSize = 20;

    public void getDetails(boolean isRefresh,String assetId, String type,String projId,String description) {
        pageNum = isRefresh ? 1 : pageNum + 1;
        Map<String, Object> map = new HashMap<>();
        map.put("assetId",assetId);
        map.put("pageNum",pageNum);
        map.put("pageSize",pageSize);
        map.put("type",type);
        if (!StringUtils.isEmpty(description)){
            map.put("description",description);
        }

        getApi(UserApi.class).apiGetHistory(getDefaultAddress() + Url.GET_RUN_LIST_PAGE, UserHelper.getToken(),projId,map)
                .compose(new ResponseTransformer<>(this.<RunListPagerBean>bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<RunListPagerBean>(view) {
                    @Override
                    public void success(RunListPagerBean baseData) {
                        view.getHistory(baseData,isRefresh);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);

                    }

                    @Override
                    public void onRequestAgain() {

                    }
                });
    }

}
